﻿using System.Net.Http;
using System.Text;
using System.Text.Json;

namespace TianlalaHSB.Utils;

public static class HttpUtil
{
    private const string Url = "http://dhqt.tianlala.com:10189/citic/execute?code=";

    public static string GetHeadReqSerialNo()
    {
        return "223018152231000008" + DateTime.Now.ToString("yyyyMMddHHmmss");
    }

    public static async Task<string> Request(string code, object body)
    {
        var httpClient = new HttpClient(); // 创建HttpClient实例
        var jsonContent = JsonSerializer.Serialize(body); //序列化为JSON字符串
        var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");

        var response = await httpClient.PostAsync(Url + code, content); // 发送POST请求
        response.EnsureSuccessStatusCode(); // 确保请求成功
        return await response.Content.ReadAsStringAsync(); // 读取响应内容
    }
}